//
//  LoginTextField.m
//  Futures
//
//  Created by Cheng on 2017/7/17.
//  Copyright © 2017年 Cheng. All rights reserved.
//

#import "LoginTextField.h"

@interface LoginTextField() <UITextFieldDelegate>

@end

@implementation LoginTextField 

- (instancetype)initWithCoder:(NSCoder *)coder
{
    self = [super initWithCoder:coder];
    if (self) {
        [self initFromXIB];
    }
    return self;
}

- (void)initFromXIB{
    UINib *nib = [UINib nibWithNibName:@"LoginTextField" bundle:nil];
    self.content = (LoginTextField *)[nib instantiateWithOwner:self options:nil].firstObject;
    self.content.frame = self.bounds;
    [self initalization];
    [self addSubview:self.content];
}

- (void)initalization{
    
    self.textField.placeholder = @"请输入手机号码";
    self.textField.textColor = [UIColor whiteColor];
    //    第二种
    [self.textField setValue:UICOLOR_RGB_Alpha(0x999999, 1) forKeyPath:@"_placeholderLabel.textColor"];
    [self.textField setAutocorrectionType: UITextAutocorrectionTypeNo]; // 关闭系统词汇联想
    [self.textField setClearButtonMode:UITextFieldViewModeWhileEditing];//编辑时会出现个修改X
    [self.textField setAutocapitalizationType:UITextAutocapitalizationTypeNone]; //关闭首字母大写
    [self.textField setReturnKeyType:UIReturnKeyNext];//键盘下一步Next
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textDidChange) name:UITextFieldTextDidChangeNotification object:self.textField];
}

-(void)dealloc{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

-(void)textDidChange{
    
    MYLog(@"%@",self.textField.text);
    if ([_delegate respondsToSelector:@selector(textDidChange:)]) {
        [_delegate textDidChange:self.textField.text];
    }
}

- (void)setLoginTextFieldWithTitle:(NSString *)title placeholder:(NSString *)placeHolder{
    self.title.text = title;
    self.textField.placeholder = placeHolder;
    
}


- (void)textFieldDidBeginEditing:(UITextField *)textField{
    MYLog(@"input");
}

- (void)textFieldDidEndEditing:(UITextField *)textField{
    
    MYLog(@"input");
}


//- (void)awakeFromNib{
//    [super awakeFromNib];
//    
////    //第一种
////    
////    UIColor *color = [UIColor whiteColor];
////    _userName.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"用户名" attributes:@{NSForegroundColorAttributeName: color}];
////    
////    
//    //第二种
//    [self.textField setValue:UICOLOR_RGB_Alpha(0x202020, 1) forKeyPath:@"_placeholderLabel.textColor"];
//}

@end
